function [RBar2_se,RBar2_fractile,beta_se,beta_fractile] = getRBar2SEboot(Y,X,window,numBoot)

data   = [Y X];
T      = size(Y,1);
nx     = size(X,2);
bsdata = block_bootstrap(data,window,numBoot);
Yboot  = squeeze(bsdata(:,1,:));
Xboot  = squeeze(bsdata(:,2:end,:));
RBar2boot = zeros(1,numBoot);
betaBoot = zeros(size(X,2),numBoot);
for b=1:numBoot
    %results=nwest(Yboot(:,b),Xboot(:,:,b),0);
    %R2boot(1,b) = results.rsqr;
    %betaBoot(:,b) = results.beta;
    beta = (Xboot(:,:,b)'*Xboot(:,:,b))\(Xboot(:,:,b)'*Yboot(:,b));
    resid = Yboot(:,b)-Xboot(:,:,b)*beta;
    ym    = Yboot(:,b) - mean(Yboot(:,b));
    RBar2boot(1,b) = 1-((resid'*resid)/(T-nx))/((ym'*ym)/(T-1));
    betaBoot(:,b) = beta;
end
RBar2_se = std(RBar2boot);
RBar2_fractile = prctile(RBar2boot,[2.5 97.5]);
beta_se = std(betaBoot,0,2);
beta_fractile = prctile(betaBoot,[2.5 97.5],2);